﻿<%@ WebHandler Language="C#" Class="ImgCode" %>

using System;
using System.Web;

public class ImgCode : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
       
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        int width = 200;
        int height = 30;

        try
        {
            width = Convert.ToInt32(context.Request.QueryString["w"]);
            height = Convert.ToInt32(context.Request.QueryString["h"]);
        }
        catch (Exception)
        {
            // Nothing
        }

        // 从 Session 中读取验证码，并创建图片
        CaptchaImage.CaptchaImage ci = new CaptchaImage.CaptchaImage(FTchina.Library.RequestHelper.GetCookie("CaptchaImageText").ToString(), width, height, "Consolas");

        // 输出图片
        context.Response.Clear();
        context.Response.ContentType = "image/jpeg";

        ci.Image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

        ci.Dispose();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}